/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shareloke.demo.entity;

import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_erupt.Tpl;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.jpa.model.MetaModelCreateVo;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * 描述：
 *
 * @author shareloke
 * @time 2024/11/4 01:28
 */
@Erupt(name = "简单的例子", rowOperation = {
        @RowOperation(
                title = "自定义按钮1",
                icon = "fa fa-eye",
                mode = RowOperation.Mode.BUTTON,
                type = RowOperation.Type.TPL,
                tpl = @Tpl(
                        path = "/tpl/common/tmp.ftl",
                        params = "btn1", // 设置vue 模板的名字
                        tplHandler = Simple.class
                )
        ),
        @RowOperation(
                title = "自定义按钮2",
                icon = "fa fa-user",
                type = RowOperation.Type.TPL,
                mode = RowOperation.Mode.BUTTON,
                tpl = @Tpl(
                        path = "/tpl/common/tmp.ftl",
                        params = "btn2", // 设置vue 模板的名字
                        tplHandler = Simple.class
                )
        )
})
@Table(name = "t_simple")
@Entity
@Getter
@Setter
public class Simple extends MetaModelCreateVo implements Tpl.TplHandler {

    //文本输入
    @EruptField(
            views = @View(title = "文本"),
            edit = @Edit(title = "文本")
    )
    private String input;

    //数值输入
    @EruptField(
            views = @View(title = "数值"),
            edit = @Edit(title = "数值")
    )
    private Integer number = 100;

    //布尔选择
    @EruptField(
            views = @View(title = "布尔"),
            edit = @Edit(title = "布尔")
    )
    private Boolean bool;

    //时间选择
    @EruptField(
            views = @View(title = "时间"),
            edit = @Edit(title = "时间", dateType = @DateType(type = DateType.Type.DATE_TIME))
    )
    private LocalDateTime date;

    @Override
    public void bindTplData(Map<String, Object> binding, String[] params) {
        if (params != null && params.length > 0) {
            // 指定vue 模板的名字，然后在模板中通过 vue_tmp_name 获取，最后由vue3-sfc-loader 去加载指定的vue 模板
            binding.put("vue_tmp_name", params[0]);
        }
    }
}
